define(['jquery', 'bootstrap', 'utilback', 'table', 'form'], function ($, undefined, Utilback, Table, Form) {

    var Controller = {
    	config: {
            get_dic: '/dic/read/detail',
            get_param: '/param/read/detail',
    	},
        init: function () {
            this.initDic();
            this.initParam();
            this.initSecond();
        },
        initDic:function(){
            // 初始化表格参数配置
            $('[href="#dic"]').on('click',function(){
                Table.api.init({
                    singleSelect: true,
                    extend: {
                        index_url: './json/GYK.json', // 查询列表
                        del_url: '/analysis', // 删除
                        add_url:'',
                        multi_url: '/analysis',
                    }
                });
            });
            $('[href="#dic"]').click();
            var table = $("#dicTable");

            // 初始化表格
            table.bootstrapTable({
                toolbar:'#toolbar1',
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                method:'get',
                showExport:false,
                showToggle: false,
                columns: [
                        [
                            {field: 'state', checkbox: true, },
                             {field: 'id', title: 'ID'},
                             {field: 'date', title: '编号'},
                             {field: 'carNum', title: "年月"},
                             {field: 'driver', title: "网工区"},
                             {field: 'learnDrive', title: "当月天数"},
                             {field: 'outTime', title: "作业天数"},
                             {field: 'location', title: "作业次数"},
                             {field: 'fillFull', title: '文件个数之和'},
                             {field:'check',title:'审核'},
                             {field:'btn',title:"操作",formatter : function (value,row,index) {
                                return Table.api.formatter.addtabs('详情',row,index,$.fn.bootstrapTable.defaults.extend.info_url);
                            }},
                        ]
                    // [
                    //     {field: 'state', checkbox: true, },
                    //     {field: 'id', title: 'ID'},
                    //     {field: 'date', title: '日期'},
                    //     {field: 'carNum', title: "轨道车号"},
                    //     {field: 'driver', title: "司机"},
                    //     {field: 'learnDrive', title: "学习司机"},
                    //     {field: 'outTime', title: "出入轨时间"},
                    //     {field: 'location', title: "网检作业地点"},
                    //     {field: 'fillFull', title: '文件完整'},
                    //     {field: 'outCheck', title: '出库试验'},
                    //     {field: 'press', title: "按压定标"},
                    //     {field: 'conclusion', title: "分析结论"},
                    //     {field: 'analyzeMan', title: "分析员"},
                    //     {field: 'jobStart', title: "作业起点"},
                    //     {field: 'jobEnd', title: "作业终点"},
                    //     {field: 'fillNum', title: "文件个数"},
                    //     {field: 'netWork', title: "网工区"},
                    //     {field: 'commandReveal', title: "揭示命令"},
                    //     {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                    //             if(row.userType == 3) {
                    //                 return '';
                    //             }
                    //             return Table.api.formatter.operate.call(this, value, row, index, table);
                    //         }}
                    // ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
           },
           initParam:function(){
                var i = 0;
                var paramTable = $('#paramTable');
                $('[href="#param"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/GYK.json', // 查询列表
                            del_url: '/analysis', // 删除
                            add_url:'',
                            multi_url: '/analysis', 
                        }
                    });
                    if(i === 0){
                        
                        // 初始化表格
                        paramTable.bootstrapTable({
                            toolbar:'#toolbar2',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field: 'state', checkbox: true,},
                                    {field: 'id', title: 'ID'},
                                    {field: 'data', title: '日期'},
                                    {field: 'carNum', title: "轨道车号"},
                                    {field: 'driver', title: "司机"},
                                    {field: 'learnDrive', title: "学习司机"},
                                    {field: 'outTime', title: "出入轨时间"},
                                    {field: 'location', title: "网检作业地点"},
                                    {field: 'fillFull', title: '文件完整'},
                                    {field: 'outCheck', title: '出库试验'},
                                    {field: 'press', title: "按压定标"},
                                    {field: 'conclusion', title: "分析结论"},
                                    {field: 'analyzeMan', title: "分析员"},
                                    {field: 'jobStart', title: "作业起点"},
                                    {field: 'jobEnd', title: "作业终点"},
                                    {field: 'fillNum', title: "文件个数"},
                                    {field: 'netWork', title: "网工区"},
                                    {field: 'commandReveal', title: "揭示命令"},
                                    {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                            return Table.api.formatter.operate.call(this, value, row, index,paramTable);
                                }}
                                ]
                            ]
                        });
                        Table.api.bindevent(paramTable);
                        i++;
                    }
                });
           },
           initSecond:function(){
                var i = 0;
                var secondTable = $('#secondTable');
                $('[href="#second"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/GYK.json', // 查询列表
                            del_url: '/analysis', // 删除
                            multi_url: '/analysis', 
                        }
                    });
                    if(i === 0){
                        secondTable.bootstrapTable({
                            toolbar:'#toolbar3',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field:'state',checkbox:true},
                                    {field: 'id', title: 'ID'},
                                    {field:'netWork',title:'网工区'},
                                    {field:'carNum',title:'车号'},
                                    {field:'date',title:'日期'},
                                    {field:'driver',title:'司机'},
                                    {field:'learnDrive',title:'学习司机'},
                                    {field:'outTime',title:'出库时间'},
                                    {field:'inTime',title:'入库时间'},
                                    {field:'networkDistance',title:'网检作业地点'},
                                    {field:'fileNum',title:'文件个数'},
                                    {field:'revealOrder',title:'揭示命令'},
                                    {field:'fileFull',title:'文件完整'},
                                    {field:'outTest',title:'出库试验'},
                                    {field:'picketage',title:'按压定标'},
                                ]
                            ]
                        });
                        Table.api.bindevent(secondTable);
                        i++;
                    }
                })
           },

        edit: function () { // 初始化编辑页面
            Form.api.bindevent($("form[role=form]"));
            Form.api.fill($("form[role=form]"),'./json/GYK.json',1);
        	// Util.api.initSelectTree({
         //    	checkParent: true,
         //    	parentEle: 'department',
         //        url:'',
        	// 	// url: '/dept/read/list',
        	// 	data: JSON.stringify({keyword:''}),
        	// 	resetData: function(data) {
        	// 	   for(var i=0;i<data.length;i++) {
        	// 		   if(data[i].leaf == 0) {
        	// 			   data[i]['open'] = true;
        	// 		   }
        	// 		   data[i]['pId'] = data[i].parentId;
        	// 		   data[i]['name'] = data[i].deptName;
        	// 	   }
        	// 	   return data;
         //    	}
         //    });
        	// var id = Util.api.query('id');
        	// var t = Util.api.query('t');
        	// if(id && t === 'U') {
        	// 	Form.api.fill($('#edit-form'), Controller.config.get_url, id, function(data) {
        	// 		$('[name="enable"]').bootstrapSwitch('state', data.enable == '1');
        	// 	});
        	// }
        },
        update: function() {
            Form.api.bindevent($("form[role=form]"));
        	Util.api.ajax({
        		type: 'GET',
        		// url: '/user/read/current'
                url:'',
        	}, function(data) {
        		$('#edit-form').autofill(data);
        	});
        }
    };
    return Controller;
     
});